CountBranchedNcK <- function(C,K) {
  
  L = 1
  total = 0
  if (K == 1) {
    total = K
  }
  else {
    for (a in L:C) {
      total = NewLoop(C,K,L+1,a,total)
      print(a)
    }
  }
  
  print(total)
  return(total)
}
  
#=======================================================
NewLoop <- function(C,K,L,A,count) { #M) {
  
#   for (a in A:C) {
#     if (L==K) {
#       count = count +1 }
#     else {
#       count = NewLoop(C,K,L+1,a,count)
#     }
# #     print(c(C,K,L,a,count))
#   }
  
  if (L==K) {
    count = count + (C-A+1)
  }
  else {
    for (a in A:C) {
      count = NewLoop(C,K,L+1,a,count)
    }
    #     print(c(C,K,L,a,count))
  }
  return(count)
}